/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MyGUIJFrame.java
 *
 * Created on Nov 15, 2009, 10:39:18 PM
 */
package MyCalculator;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import javax.swing.JFileChooser;

/**
 *
 * @author fire
 */
public class MyGUIJFrame extends javax.swing.JFrame {

    private int[] xs = new int[519];
    private int[] ys = new int[519];
    private int offset = 150;
    Calculator_GUI_Utilities myGUIUtil = new Calculator_GUI_Utilities();

    public MyGUIJFrame() {
        
        initComponents();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    private void updateStackView() {
        if (!myGUIUtil.Calc_Stck.isEmpty()) {
            double[] list2Show = new double[myGUIUtil.Calc_Stck.size()];
            String StackList = "";
            for (int i = 0; i < list2Show.length; i++) {
                double temp = myGUIUtil.Calc_Stck.pop();
                StackList += (temp + "\n");
                list2Show[i] = temp;
            }

            //push everything back to restore the stack;
            for (int i = list2Show.length - 1; i >= 0; i--) {
                myGUIUtil.Calc_Stck.push(list2Show[i]);
            }
            System.out.println(StackList);
            StackViewer.setText(StackList);

        } else {
            StackViewer.setText("");
        }
    }
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        inputField = new javax.swing.JTextField();
        C_Label = new javax.swing.JLabel();
        plotButtom = new javax.swing.JButton();
        PlotCanvas = new PlotCanvas();
        sinButton = new javax.swing.JButton();
        CosButton = new javax.swing.JButton();
        tanButton = new javax.swing.JButton();
        asinButton = new javax.swing.JButton();
        acosButton = new javax.swing.JButton();
        atanButton = new javax.swing.JButton();
        log10Button = new javax.swing.JButton();
        lnButton = new javax.swing.JButton();
        log2Button = new javax.swing.JButton();
        factButton = new javax.swing.JButton();
        sqrtButton = new javax.swing.JButton();
        complementButton = new javax.swing.JButton();
        invertButton = new javax.swing.JButton();
        addButton = new javax.swing.JButton();
        subButton = new javax.swing.JButton();
        multButton = new javax.swing.JButton();
        divButton = new javax.swing.JButton();
        swapButton = new javax.swing.JButton();
        x2yButton = new javax.swing.JButton();
        modeButton = new javax.swing.JButton();
        std_divButton = new javax.swing.JButton();
        meanButton = new javax.swing.JButton();
        medianButton = new javax.swing.JButton();
        rangeButton = new javax.swing.JButton();
        maxButton = new javax.swing.JButton();
        minButton = new javax.swing.JButton();
        sumButton = new javax.swing.JButton();
        PUSH_Buttom = new javax.swing.JButton();
        polyInput = new javax.swing.JTextField();
        PolynomialField = new java.awt.Label();
        jScrollPane1 = new javax.swing.JScrollPane();
        StackViewer = new javax.swing.JTextArea();
        xLower = new javax.swing.JTextField();
        xUpper = new javax.swing.JTextField();
        yLower = new javax.swing.JTextField();
        yUpper = new javax.swing.JTextField();
        x_upper = new javax.swing.JLabel();
        x_lower = new javax.swing.JLabel();
        y_upper = new javax.swing.JLabel();
        y_lower = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        PolyMsg = new javax.swing.JLabel();
        OpenFile = new javax.swing.JButton();
        SaveFile = new javax.swing.JButton();
        StackClear = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("↑↑ RPN Graphic Scientific Calculator ↑↑By ChengXuan. Liu Li. Zi ye");
        setBackground(new java.awt.Color(255, 255, 255));

        inputField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                inputFieldActionPerformed(evt);
            }
        });

        C_Label.setText("Input Number Field");

        plotButtom.setActionCommand("Plot");
        plotButtom.setLabel("Plot");
        plotButtom.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PlotActionPerformed(evt);
            }
        });

        PlotCanvas.setBackground(new java.awt.Color(0, 0, 0));
        PlotCanvas.setForeground(new java.awt.Color(255, 255, 255));

        sinButton.setActionCommand("sin");
        sinButton.setLabel("Sin");
        sinButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sinButtonActionPerformed(evt);
            }
        });

        CosButton.setText("Cos");
        CosButton.setActionCommand("sin");
        CosButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CosActionPerformed(evt);
            }
        });

        tanButton.setText("tan");
        tanButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TanActionPerformed(evt);
            }
        });

        asinButton.setText("asin");
        asinButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AsinActionPerformed(evt);
            }
        });

        acosButton.setText("acos");
        acosButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AcosActionPerformed(evt);
            }
        });

        atanButton.setText("atan");
        atanButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AtanActionPerformed(evt);
            }
        });

        log10Button.setText("log10");
        log10Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Log10ActionPerformed(evt);
            }
        });

        lnButton.setText("ln");
        lnButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LnActionPerformed(evt);
            }
        });

        log2Button.setText("log2");
        log2Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                log2ActionPerformed(evt);
            }
        });

        factButton.setText("factorial");
        factButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                factorialActionPerformed(evt);
            }
        });

        sqrtButton.setText("sqrt");
        sqrtButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SqrtActionPerformed(evt);
            }
        });

        complementButton.setText("complement");
        complementButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                complementActionPerformed(evt);
            }
        });

        invertButton.setText("invert");
        invertButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                invertActionPerformed(evt);
            }
        });

        addButton.setText("Add");
        addButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddActionPerformed(evt);
            }
        });

        subButton.setText("sub");
        subButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                subActionPerformed(evt);
            }
        });

        multButton.setText("mult");
        multButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MultActionPerformed(evt);
            }
        });

        divButton.setText("Div");
        divButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DivActionPerformed(evt);
            }
        });

        swapButton.setText("Swap");
        swapButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SwapActionPerformed(evt);
            }
        });

        x2yButton.setText("x^y");
        x2yButton.setActionCommand("x2y");
        x2yButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                x2yActionPerformed(evt);
            }
        });

        modeButton.setText("mode");
        modeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                modeActionPerformed(evt);
            }
        });

        std_divButton.setText("std_div");
        std_divButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                std_divActionPerformed(evt);
            }
        });

        meanButton.setText("mean");
        meanButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                meanActionPerformed(evt);
            }
        });

        medianButton.setText("median");
        medianButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                medianActionPerformed(evt);
            }
        });

        rangeButton.setText("range");
        rangeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rangeActionPerformed(evt);
            }
        });

        maxButton.setText("max");
        maxButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MaxActionPerformed(evt);
            }
        });

        minButton.setText("min");
        minButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                minActionPerformed(evt);
            }
        });

        sumButton.setText("sum");
        sumButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sumActionPerformed(evt);
            }
        });

        PUSH_Buttom.setText("PUSH");
        PUSH_Buttom.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PUSHActionPerformed(evt);
            }
        });

        polyInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                polyInputActionPerformed(evt);
            }
        });

        PolynomialField.setFont(new java.awt.Font("DejaVu Sans", 0, 12));
        PolynomialField.setText("Polynomial Input Field");

        StackViewer.setColumns(20);
        StackViewer.setEditable(false);
        StackViewer.setRows(5);
        jScrollPane1.setViewportView(StackViewer);

        xLower.setText("10");

        xUpper.setText("-10");
        xUpper.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                xUpperActionPerformed(evt);
            }
        });

        yLower.setText("5");

        yUpper.setText("-5");

        x_upper.setText("xUpper");

        x_lower.setText("xLower");

        y_upper.setText("yUpper");

        y_lower.setText("yLower");

        jLabel1.setText("Stack View");

        OpenFile.setText("Open");
        OpenFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OpenFileActionPerformed(evt);
            }
        });

        SaveFile.setText("Save");
        SaveFile.setMaximumSize(new java.awt.Dimension(59, 23));
        SaveFile.setMinimumSize(new java.awt.Dimension(59, 23));
        SaveFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SaveFileActionPerformed(evt);
            }
        });

        StackClear.setText("Clear Stack");
        StackClear.setActionCommand("ClearStack");
        StackClear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                StackClearActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(invertButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(modeButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(sqrtButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(swapButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(x2yButton))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(std_divButton)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(meanButton))
                                    .addComponent(PolynomialField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(medianButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(plotButtom)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                        .addComponent(rangeButton)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(maxButton)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(minButton)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(sumButton))))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(sinButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(addButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(subButton)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(multButton)
                                        .addGap(4, 4, 4)
                                        .addComponent(divButton, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(2, 2, 2)
                                        .addComponent(factButton, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(complementButton))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(CosButton)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(tanButton)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(asinButton)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(acosButton)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(atanButton))
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(200, 200, 200)
                                                .addComponent(C_Label)))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(PUSH_Buttom)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(StackClear, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(log10Button)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(lnButton)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(log2Button)))))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 2, Short.MAX_VALUE))
                            .addComponent(inputField, javax.swing.GroupLayout.PREFERRED_SIZE, 253, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(polyInput, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(PlotCanvas, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 519, Short.MAX_VALUE)))
                        .addGap(44, 44, 44)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 92, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(x_upper)
                                    .addComponent(jLabel1)
                                    .addComponent(xLower, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
                                    .addComponent(x_lower)
                                    .addComponent(xUpper, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
                                    .addComponent(y_upper)
                                    .addComponent(yLower, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
                                    .addComponent(yUpper, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
                                    .addComponent(y_lower)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(10, 10, 10)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(SaveFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(OpenFile))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE))))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(54, 54, 54)
                        .addComponent(PolyMsg, javax.swing.GroupLayout.PREFERRED_SIZE, 439, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(inputField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(PUSH_Buttom)
                            .addComponent(StackClear)
                            .addComponent(C_Label))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(sinButton)
                            .addComponent(log10Button)
                            .addComponent(lnButton)
                            .addComponent(log2Button)
                            .addComponent(CosButton)
                            .addComponent(tanButton)
                            .addComponent(asinButton)
                            .addComponent(acosButton)
                            .addComponent(atanButton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(addButton)
                            .addComponent(subButton)
                            .addComponent(multButton)
                            .addComponent(divButton)
                            .addComponent(factButton)
                            .addComponent(complementButton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(invertButton)
                            .addComponent(modeButton)
                            .addComponent(sqrtButton)
                            .addComponent(swapButton)
                            .addComponent(x2yButton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(std_divButton)
                            .addComponent(meanButton)
                            .addComponent(medianButton)
                            .addComponent(rangeButton)
                            .addComponent(maxButton)
                            .addComponent(minButton)
                            .addComponent(sumButton))
                        .addGap(14, 14, 14)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(PolynomialField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(plotButtom))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(polyInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel1)))
                .addGap(3, 3, 3)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(PlotCanvas, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(15, 15, 15)
                        .addComponent(x_upper)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(xLower, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(x_lower)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(xUpper, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(y_upper)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(yLower, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(y_lower)
                        .addGap(15, 15, 15)
                        .addComponent(yUpper, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(OpenFile)
                        .addGap(18, 18, 18)
                        .addComponent(SaveFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
                .addComponent(PolyMsg, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void inputFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inputFieldActionPerformed
    }//GEN-LAST:event_inputFieldActionPerformed

    private void PlotActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PlotActionPerformed


        try {
            ClearAllcoords();
            ((PlotCanvas) PlotCanvas).update(PlotCanvas.getGraphics());

            
            double [] x_axis=new double[519];
            double [] y_axis=new double[519];
            for(int k=0;k<519;k++){
                x_axis[k]=0;
            }

            double [] loadedPloy=new double[519];
            double [] rootList;
            int [] yi=new int[519];
            PloyCalc b = new PloyCalc();
            String PolyString = polyInput.getText();
            double x_L = Double.parseDouble(xLower.getText());
            double x_U = Double.parseDouble(xUpper.getText());
            double y_L = Double.parseDouble(yLower.getText());
            double y_U = Double.parseDouble(yUpper.getText());
            double[][] polyTermArray = myGUIUtil.parsePoly(PolyString);
            loadedPloy=b.CalcthePoly(polyTermArray, x_U, x_L, 519);
            for (int j = 0; j < 519; j++) {
                yi[j] = j;
            }
            //Plotting X-axis
             double[] xas=new double[xs.length];
             for (int l=0;l<xs.length;l++){
                 xas[l]=0;
             }
             this.setXcoords(xas, y_L, y_U);
             this.setYcoords(yi, 100, -100);
            ((PlotCanvas) PlotCanvas).paint(xs, ys, 519, PlotCanvas.getGraphics());
            if((x_L*x_U)<0){
                int nega_pix=(int)((x_U)/((x_U-x_L)/519));
                for (int t=0;t<519;t++){
                    if(t<nega_pix)
                        xs[t]=Integer.MAX_VALUE;
                    else if(t==nega_pix)
                        xs[t]=0;
                    else
                        xs[t]=Integer.MIN_VALUE;
                }
            }
            
            //this.setXcoords(yas, y_L, y_U);
             this.setYcoords(yi, 100, -100);
            ((PlotCanvas) PlotCanvas).paint(xs, ys, 519, PlotCanvas.getGraphics());

            this.setXcoords(loadedPloy, y_L, y_U);
            this.setYcoords(yi, 100, -100);
            ((PlotCanvas) PlotCanvas).paint(xs, ys, 519, PlotCanvas.getGraphics());

            rootList=b.rootFinding(loadedPloy, polyTermArray,  x_U, x_L, 519);

            String TestedPrint="";
            for (int i=0; i<rootList.length; i++){
                TestedPrint+=(rootList[i]+" ");
            }
            PolyMsg.setText("The Roots are: "+TestedPrint);
            /*
            String TestedPrint="";
            for (int i=0; i<polyTermArray.length; i++){
                TestedPrint+=("( "+polyTermArray[i][0]+","+polyTermArray[i][1]+" )");
            }
            */

            
            
            //PolyMsg.setText(TestedPrint);
        } catch (NumberFormatException e) {
            PolyMsg.setText("Invalid Input, enter again please.");
        } catch (PolyStringFormatException e) {
            PolyMsg.setText("Invalid Poly, enter again please.");
        }



        /*
        System.out.println("actionPerformed: " + evt.getSource().toString());
        if (evt.getActionCommand().equals("Plot")) {
            System.out.println("Plotting incoming");
            ((PlotCanvas) PlotCanvas).paint(xs, ys, 519, PlotCanvas.getGraphics());
            //canvas.repaint();
        }
        */
    }//GEN-LAST:event_PlotActionPerformed

    private void sinButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sinButtonActionPerformed
        try {
            double reslut = myGUIUtil.doCalculation(1);
            inputField.setText("" + reslut);
        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }
        this.updateStackView();
    }//GEN-LAST:event_sinButtonActionPerformed

    private void CosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CosActionPerformed
        try {
            double reslut = myGUIUtil.doCalculation(2);
            inputField.setText("" + reslut);
            this.updateStackView();
        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }


    }//GEN-LAST:event_CosActionPerformed

    private void TanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TanActionPerformed
        try {
            double reslut = myGUIUtil.doCalculation(3);
            inputField.setText("" + reslut);
            this.updateStackView();
        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }

    }//GEN-LAST:event_TanActionPerformed

    private void AsinActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AsinActionPerformed
        try {
            double reslut = myGUIUtil.doCalculation(4);
            inputField.setText("" + reslut);
            this.updateStackView();
        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }

    }//GEN-LAST:event_AsinActionPerformed

    private void AcosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AcosActionPerformed
        try {
            double reslut = myGUIUtil.doCalculation(5);
            inputField.setText("" + reslut);
            this.updateStackView();
        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }

    }//GEN-LAST:event_AcosActionPerformed

    private void AtanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AtanActionPerformed
        try {
            double reslut = myGUIUtil.doCalculation(6);
            inputField.setText("" + reslut);
            this.updateStackView();
        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }

    }//GEN-LAST:event_AtanActionPerformed

    private void Log10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Log10ActionPerformed
        try {
            double reslut = myGUIUtil.doCalculation(7);
            inputField.setText("" + reslut);
            this.updateStackView();
        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }

    }//GEN-LAST:event_Log10ActionPerformed

    private void LnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LnActionPerformed
        try {
            double reslut = myGUIUtil.doCalculation(8);
            inputField.setText("" + reslut);
            this.updateStackView();
        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }

    }//GEN-LAST:event_LnActionPerformed

    private void log2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_log2ActionPerformed
        try {
            double reslut = myGUIUtil.doCalculation(9);
            inputField.setText("" + reslut);
            this.updateStackView();
        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }

    }//GEN-LAST:event_log2ActionPerformed

    private void factorialActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_factorialActionPerformed
        try {
            double temp=myGUIUtil.Calc_Stck.pop();
            if(temp<=0){
                inputField.setText("Need a Possitive number on the top");
                myGUIUtil.Calc_Stck.push(temp);
            }else{
                myGUIUtil.Calc_Stck.push(temp);
                double reslut = myGUIUtil.doCalculation(10);
                inputField.setText("" + reslut);
                this.updateStackView();
            }
        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }


    }//GEN-LAST:event_factorialActionPerformed

    private void SqrtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SqrtActionPerformed
        try {
            double reslut = myGUIUtil.doCalculation(11);
            inputField.setText("" + reslut);
            this.updateStackView();
        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }

    }//GEN-LAST:event_SqrtActionPerformed

    private void complementActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_complementActionPerformed
        try {
            double reslut = myGUIUtil.doCalculation(12);
            inputField.setText("" + reslut);
            this.updateStackView();
        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }

    }//GEN-LAST:event_complementActionPerformed

    private void invertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_invertActionPerformed
        try {
            double temp=myGUIUtil.Calc_Stck.pop();
            if(temp==0){
                inputField.setText("Can not devided by Zero");
                myGUIUtil.Calc_Stck.push(temp);
            }else{
                myGUIUtil.Calc_Stck.push(temp);
                double reslut = myGUIUtil.doCalculation(13);
                inputField.setText("" + reslut);
                this.updateStackView();
            }

        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }
    }//GEN-LAST:event_invertActionPerformed

    private void AddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddActionPerformed
        try {
            double reslut = myGUIUtil.doCalculation(14);
            inputField.setText("" + reslut);
            this.updateStackView();
        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }

    }//GEN-LAST:event_AddActionPerformed

    private void subActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_subActionPerformed
        try {
            double reslut = myGUIUtil.doCalculation(15);
            inputField.setText("" + reslut);
            this.updateStackView();
        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }


    }//GEN-LAST:event_subActionPerformed

    private void MultActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MultActionPerformed
        try {
            double reslut = myGUIUtil.doCalculation(16);
            inputField.setText("" + reslut);
            this.updateStackView();
        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }


    }//GEN-LAST:event_MultActionPerformed

    private void DivActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DivActionPerformed
        try {
            double temp=myGUIUtil.Calc_Stck.pop();
            if(temp==0){
                inputField.setText("Can not devided by Zero");
                myGUIUtil.Calc_Stck.push(temp);
            }else{
                myGUIUtil.Calc_Stck.push(temp);
                double reslut = myGUIUtil.doCalculation(17);
                System.out.println(""+reslut);
                inputField.setText("" + reslut);
                this.updateStackView();
            }

        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        //} catch ( e){

        }

    }//GEN-LAST:event_DivActionPerformed

    private void SwapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SwapActionPerformed
        try {
            double reslut = myGUIUtil.doCalculation(18);
            inputField.setText("" + reslut);
            this.updateStackView();
        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }


    }//GEN-LAST:event_SwapActionPerformed

    private void x2yActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_x2yActionPerformed
        try {
            double reslut = myGUIUtil.doCalculation(19);
            inputField.setText("" + reslut);
            this.updateStackView();
        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }


    }//GEN-LAST:event_x2yActionPerformed

    private void modeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_modeActionPerformed
        try {
            double reslut = myGUIUtil.doCalculation(28);
            inputField.setText("" + reslut);
            this.updateStackView();
        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }


    }//GEN-LAST:event_modeActionPerformed

    private void std_divActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_std_divActionPerformed
        try {
            double reslut = myGUIUtil.doCalculation(21);
            inputField.setText("" + reslut);
            this.updateStackView();
        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }
    }//GEN-LAST:event_std_divActionPerformed

    private void meanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_meanActionPerformed
        try {
            double reslut = myGUIUtil.doCalculation(22);
            inputField.setText("" + reslut);
            this.updateStackView();
        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }

    }//GEN-LAST:event_meanActionPerformed

    private void medianActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_medianActionPerformed
        try {
            double reslut = myGUIUtil.doCalculation(23);
            inputField.setText("" + reslut);
            this.updateStackView();
        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }

    }//GEN-LAST:event_medianActionPerformed

    private void rangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rangeActionPerformed
        //This function will behave a bit differently than others.

        try {
            double reslut = myGUIUtil.doCalculation(24);
            inputField.setText("" + reslut);
            this.updateStackView();
        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }


    }//GEN-LAST:event_rangeActionPerformed

    private void MaxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MaxActionPerformed
        try {
            double reslut = myGUIUtil.doCalculation(25);
            inputField.setText("" + reslut);
            this.updateStackView();
        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }


    }//GEN-LAST:event_MaxActionPerformed

    private void minActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_minActionPerformed
        try {
            double reslut = myGUIUtil.doCalculation(26);
            inputField.setText("" + reslut);
            this.updateStackView();
        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }


    }//GEN-LAST:event_minActionPerformed

    private void sumActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sumActionPerformed
        try {
            double reslut = myGUIUtil.doCalculation(27);
            inputField.setText("" + reslut);
            this.updateStackView();
        } catch (java.util.EmptyStackException e) {
            inputField.setText("Not enough number on the stack");
        }

    }//GEN-LAST:event_sumActionPerformed

    private void PUSHActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PUSHActionPerformed
        if (evt.getActionCommand().equals("PUSH")) {
            try {
                myGUIUtil.Push_Number(Double.parseDouble(inputField.getText()));
                //inputField.setText("");
            } catch (NumberFormatException e) {
                inputField.setText("Invalid Input, enter again please.");
            }
            this.updateStackView();
        }

    }//GEN-LAST:event_PUSHActionPerformed

    private void polyInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_polyInputActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_polyInputActionPerformed

    private void xUpperActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_xUpperActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_xUpperActionPerformed

    private void OpenFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OpenFileActionPerformed
        int returnVal = fc.showOpenDialog(MyGUIJFrame.this);

        double [] loadedFilex=new double[519];
        int [] loadedFiley=new int[519];
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            try{
            //double x_L = Double.parseDouble(xLower.getText());
            //double x_U = Double.parseDouble(xUpper.getText());
            //double y_L = Double.parseDouble(yLower.getText());
            //double y_U = Double.parseDouble(yUpper.getText());

                BufferedReader in = new BufferedReader(new FileReader(file));

                //Load the range first.
                double x_L=Double.parseDouble(in.readLine());
                double x_U=Double.parseDouble(in.readLine());
                double y_L=Double.parseDouble(in.readLine());
                double y_U=Double.parseDouble(in.readLine());
                int i=0;
                String inputString=in.readLine();

                System.out.println("inputString: "+inputString);
                while(inputString!=null){
                    xs[i]=Integer.parseInt(inputString);
                    ys[i]=i;
                    i++;
                    inputString=in.readLine();
                }

                //setXcoords(loadedFilex, y_U, y_L);
                //setYcoords(loadedFiley, 100, -100);

                ((PlotCanvas) PlotCanvas).paint(xs, ys, 519, PlotCanvas.getGraphics());

            int [] yi=new int[519];
            for (int j = 0; j < 519; j++) {
                yi[j] = j;
            }
             //Plotting X-axis
             double[] xas=new double[xs.length];
             for (int l=0;l<xs.length;l++){
                 xas[l]=0;
             }
             this.setXcoords(xas, y_L, y_U);
             this.setYcoords(yi, 100, -100);
            ((PlotCanvas) PlotCanvas).paint(xs, ys, 519, PlotCanvas.getGraphics());
            if((x_L*x_U)<0){
                int nega_pix=(int)((x_U)/((x_U-x_L)/519));
                for (int t=0;t<519;t++){
                    if(t<nega_pix)
                        xs[t]=Integer.MAX_VALUE;
                    else if(t==nega_pix)
                        xs[t]=0;
                    else
                        xs[t]=Integer.MIN_VALUE;
                }
            }

            //this.setXcoords(yas, y_L, y_U);
             this.setYcoords(yi, 100, -100);
            ((PlotCanvas) PlotCanvas).paint(xs, ys, 519, PlotCanvas.getGraphics());

            }catch (NumberFormatException e){

            }catch(Exception e){

            }


        }

    }//GEN-LAST:event_OpenFileActionPerformed

    private void SaveFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveFileActionPerformed
        // TODO add your handling code here:
        int returnVal = fc.showSaveDialog(MyGUIJFrame.this);

        if(xs==null){
            PolyMsg.setText("No Plot avaiable to save");
        }else if (returnVal == JFileChooser.APPROVE_OPTION) {
            
            File file = fc.getSelectedFile();
            try{
                
                BufferedWriter out = new BufferedWriter(new FileWriter(file));
                double x_L = Double.parseDouble(xLower.getText());
                double x_U = Double.parseDouble(xUpper.getText());
                double y_L = Double.parseDouble(yLower.getText());
                double y_U = Double.parseDouble(yUpper.getText());
                System.out.println("GETS Here: "+x_L);
                out.write(x_L+"");
                out.newLine();
                out.write(x_U+"");
                out.newLine();
                out.write(y_L+"");
                out.newLine();
                out.write(y_U+"");

                for (int i=0;i<xs.length;i++){
                    out.newLine();
                    out.write(xs[i]+"");
                }
                out.close();
            }catch (NumberFormatException e){
                PolyMsg.setText("Invalid Number Format");
            }catch(Exception e){
                PolyMsg.setText("Exception occurs");
            }
        }

    }//GEN-LAST:event_SaveFileActionPerformed

    private void StackClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StackClearActionPerformed
        myGUIUtil.Calc_Stck.clear();

        this.updateStackView();
    }//GEN-LAST:event_StackClearActionPerformed
    public void setXcoords(double[] x, double upper, double lower) {
        double deltaX = (upper - lower) / 300;
        
        int i;
        for (i = 0; i < x.length; i++) {
            xs[i] = (int) ((upper-(x[i]))/ deltaX);
            //System.out.println("upper: "+ upper +" i: "+i +" xs: "+ xs[i]+ " xi: "+x[i]);
            //xs[i] = x[i] ;
        }
    }
    public void ClearAllcoords() {
        int i;
        for (i = 0; i < ys.length; i++) {
            ys[i] = Integer.MAX_VALUE;
        }
        for (i = 0; i < xs.length; i++) {
            xs[i] = Integer.MAX_VALUE;
        }
    }
    public void setYcoords(int[] y, double upper, double lower) {

        double deltaY = (upper - lower) / 300;
        int i;
        for (i = 0; i < y.length; i++) {
            ys[i] = y[i];

        }
    }
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel C_Label;
    private javax.swing.JButton CosButton;
    private javax.swing.JButton OpenFile;
    private javax.swing.JButton PUSH_Buttom;
    private java.awt.Canvas PlotCanvas;
    private javax.swing.JLabel PolyMsg;
    private java.awt.Label PolynomialField;
    private javax.swing.JButton SaveFile;
    private javax.swing.JButton StackClear;
    private javax.swing.JTextArea StackViewer;
    private javax.swing.JButton acosButton;
    private javax.swing.JButton addButton;
    private javax.swing.JButton asinButton;
    private javax.swing.JButton atanButton;
    private javax.swing.JButton complementButton;
    private javax.swing.JButton divButton;
    private javax.swing.JButton factButton;
    private javax.swing.JTextField inputField;
    private javax.swing.JButton invertButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton lnButton;
    private javax.swing.JButton log10Button;
    private javax.swing.JButton log2Button;
    private javax.swing.JButton maxButton;
    private javax.swing.JButton meanButton;
    private javax.swing.JButton medianButton;
    private javax.swing.JButton minButton;
    private javax.swing.JButton modeButton;
    private javax.swing.JButton multButton;
    private javax.swing.JButton plotButtom;
    private javax.swing.JTextField polyInput;
    private javax.swing.JButton rangeButton;
    private javax.swing.JButton sinButton;
    private javax.swing.JButton sqrtButton;
    private javax.swing.JButton std_divButton;
    private javax.swing.JButton subButton;
    private javax.swing.JButton sumButton;
    private javax.swing.JButton swapButton;
    private javax.swing.JButton tanButton;
    private javax.swing.JButton x2yButton;
    private javax.swing.JTextField xLower;
    private javax.swing.JTextField xUpper;
    private javax.swing.JLabel x_lower;
    private javax.swing.JLabel x_upper;
    private javax.swing.JTextField yLower;
    private javax.swing.JTextField yUpper;
    private javax.swing.JLabel y_lower;
    private javax.swing.JLabel y_upper;
    // End of variables declaration//GEN-END:variables
    private JFileChooser fc = new JFileChooser();
}
